package com.ruicar.afs.cloud.workflow.greatwall.controller.gtw;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruicar.afs.cloud.common.core.query.QueryCondition;
import com.ruicar.afs.cloud.common.core.util.IResponse;
import com.ruicar.afs.cloud.workflow.api.dto.afsprocess.request.*;
import com.ruicar.afs.cloud.workflow.api.dto.flowprocess.AfsFLowRequestDto;
import com.ruicar.afs.cloud.workflow.api.dto.flowprocess.WorkFlowResponse;
import com.ruicar.afs.cloud.workflow.api.dto.flowprocess.request.*;
import com.ruicar.afs.cloud.workflow.greatwall.service.gwt.GwtWorkFlowEngineProcess;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@AllArgsConstructor
@Slf4j
public class AfsToFlowEngineController {
    private final GwtWorkFlowEngineProcess gwtWorkFlowEngineProcess;

    /**
     * Afs work flow apis response
     * 业务端调用流程服务 流程发起
     *
     * @return the response
     */
    @PostMapping("/afs/workflow/startFlow")
    public IResponse<WorkFlowResponse> startFlow(@RequestBody AfsFLowRequestDto<StartFlowRequest> afsFLowRequestDto) {
        return IResponse.success(gwtWorkFlowEngineProcess.startFlow(afsFLowRequestDto.getFlowData(), afsFLowRequestDto.getBizData(), afsFLowRequestDto.getServiceName()));
    }

    @PostMapping("/afs/workflow/taskSubmit")
    public IResponse<WorkFlowResponse> taskSubmit(@RequestBody AfsFLowRequestDto<TaskSubmitRequest> afsFLowRequestDto) {
        return IResponse.success(gwtWorkFlowEngineProcess.taskSubmit(afsFLowRequestDto.getFlowData(), afsFLowRequestDto.getBizData(), afsFLowRequestDto.getServiceName()));
    }

    @PostMapping("/afs/workflow/taskReformist")
    public IResponse<WorkFlowResponse> taskReformist(@RequestBody AfsFLowRequestDto<TaskReformistRequest> afsFLowRequestDto) {
        return IResponse.success(gwtWorkFlowEngineProcess.taskReformist(afsFLowRequestDto.getFlowData(), afsFLowRequestDto.getBizData(), afsFLowRequestDto.getServiceName()));
    }


    @PostMapping("/afs/workflow/flowGiveUp")
    public IResponse<WorkFlowResponse> flowGiveUp(@RequestBody AfsFLowRequestDto<FLowGiveUpRequest> afsFLowRequestDto) {
        return IResponse.success(gwtWorkFlowEngineProcess.flowGiveUp(afsFLowRequestDto.getFlowData(), afsFLowRequestDto.getServiceName()));
    }


    @PostMapping("/afs/workflow/queryCmd")
    public IResponse<WorkFlowResponse> queryCmd(@RequestBody AfsFLowRequestDto<QueryFLowCmdRequest> afsFLowRequestDto) {
        return IResponse.success(gwtWorkFlowEngineProcess.queryCmd(afsFLowRequestDto.getFlowData(), afsFLowRequestDto.getServiceName()));
    }


    @PostMapping("/afs/workflow/queryFlowInstance")
    public IResponse<WorkFlowResponse> queryFlowInstance(@RequestBody AfsFLowRequestDto<QueryFlowInstanceRequest> afsFLowRequestDto) {
        return IResponse.success(gwtWorkFlowEngineProcess.queryFlowInstance(afsFLowRequestDto.getFlowData(), afsFLowRequestDto.getServiceName()));
    }

    @PostMapping("/afs/workflow/taskCallBack")
    public IResponse<WorkFlowResponse> taskCallBack(@RequestBody AfsFLowRequestDto<TaskCallBackRequest> afsFLowRequestDto) {
        return IResponse.success(gwtWorkFlowEngineProcess.taskCallBack(afsFLowRequestDto.getFlowData(), afsFLowRequestDto.getBizData(), afsFLowRequestDto.getServiceName()));
    }

    @PostMapping("/afs/workflow/pageQueryNode")
    public IResponse<WorkFlowResponse> pageQueryNode(@RequestBody Page page) {
        return IResponse.success(gwtWorkFlowEngineProcess.pageQueryNode(page));
    }


    @PostMapping("/afs/workflow/queryAllNode")
    public IResponse<WorkFlowResponse> queryAllNode() {
        return IResponse.success(gwtWorkFlowEngineProcess.queryAllNode());
    }


    @PostMapping("/afs/workflow/pageQueryNodeUser")
    public IResponse<WorkFlowResponse> pageQueryNodeUser(@RequestBody QueryCondition<QueryNodeUserRequest> queryNodeUserRequestQueryCondition) {
        return IResponse.success(gwtWorkFlowEngineProcess.pageQueryNodeUser(queryNodeUserRequestQueryCondition));
    }

    @PostMapping("/afs/workflow/addNodeUser")
    public IResponse<WorkFlowResponse> addNodeUser(@RequestBody AddNodeUserRequest addNodeUserRequest) {
        return IResponse.success(gwtWorkFlowEngineProcess.addNodeUser(addNodeUserRequest));
    }

    @PostMapping("/afs/workflow/changeTotalWeight")
    public IResponse<WorkFlowResponse> changeTotalWeight(@RequestBody ChangeTotalUserWeightRequest changeTotalUserWeightRequest) {
        return IResponse.success(gwtWorkFlowEngineProcess.changeTotalWeight(changeTotalUserWeightRequest));
    }

    @PostMapping("/afs/workflow/changeWeight")
    public IResponse<WorkFlowResponse> changeWeight(@RequestBody ChangeUserWeightRequest changeUserWeightRequest) {
        return IResponse.success(gwtWorkFlowEngineProcess.changeWeight(changeUserWeightRequest));
    }

    @PostMapping("/afs/workflow/clearTaskCount")
    public IResponse<WorkFlowResponse> clearTaskCount(@RequestBody List<String> userIds) {
        return IResponse.success(gwtWorkFlowEngineProcess.clearTaskCount(userIds));
    }

    @PostMapping("/afs/workflow/removeNodeUsers")
    public IResponse<WorkFlowResponse> removeNodeUsers(@RequestBody List<String> userIds) {
        return IResponse.success(gwtWorkFlowEngineProcess.removeNodeUsers(userIds));
    }

    @PostMapping("/afs/workflow/moveUserToNode")
    public IResponse<WorkFlowResponse> moveUserToNode(@RequestBody MoveUserToNewNodeRequest moveUserToNewNodeRequest) {
        return IResponse.success(gwtWorkFlowEngineProcess.moveUserToNode(moveUserToNewNodeRequest));
    }

    @PostMapping("/afs/workflow/resumeFlowInstance")
    public IResponse<WorkFlowResponse> resumeFlowInstance(@RequestBody ResumeFlowRequest resumeFlowRequest) {
        return IResponse.success(gwtWorkFlowEngineProcess.resumeFlowInstance(resumeFlowRequest));
    }


    @PostMapping("/afs/workflow/pauseFlowInstance")
    public IResponse<WorkFlowResponse> pauseFlowInstance(@RequestBody PauseFlowInstance pauseFlowInstance) {
        return IResponse.success(gwtWorkFlowEngineProcess.pauseFlowInstance(pauseFlowInstance));
    }
}
